package com.xlh.resource;

import org.springframework.core.io.UrlResource;

import java.net.MalformedURLException;

//访问网络资源
public class UrlResourceDemo {
    public static void main(String[] args) {
        loadUrlResource("https://www.baidu.com");

        loadUrlResource("file:a.txt");
    }
    //访问前缀是http、file
    public static void loadUrlResource(String path) {
        //创建实现类对象UrlResource
        try {
            UrlResource url = new UrlResource(path);
            System.out.println(url.getFilename());
            System.out.println(url.getURL());
            System.out.println(url.getDescription());
            System.out.println(url.getInputStream().read());
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        //获取资源信息
    }
}
